<?php
/**
 * Created by PhpStorm.
 * User: yuxingkui
 * Date: 17/8/11
 * Time: 下午1:16
 */
namespace App\Api\Controllers\Validators;

use Illuminate\Http\Request;
use Validator;

class ApplyValidator
{
	/**
	 * 企业申请 数据验证
	 *
	 * @param Request $request
	 * @return mixed
	 * */
	public static function apply(Request $request)
	{
		$only = ['company_name','name','scale','position','contact','remarks'];

		$rules = [
//			'company_name' => 'min:2|max:20',
			'name' => 'required|min:2',
//			'scale' => 'required',
//			'position' => 'required|min:2',
			'contact' => 'required',
		];

		$messages = [
			'company_name.required' => '请输入公司名称',
			'company_name.min' => '公司名称不能小于2个字',
			'company_name.max' => '公司名称不能大于20个字',

			'name.required' => '请输入姓名',
			'name.min' => '姓名不能小于2个字',

			'scale.required' => '请输入公司规模',

			'position.required' => '请输入职位',
			'position.min' => '职位不能小于2个字',

			'contact.required' => '请填写联系方式',


		];

		$input = $request->only($only);

		$validator = Validator::make($input, $rules, $messages);

		if ($validator->fails())
			exit(json_encode(['info'=>$validator->errors()->first(),'code'=>'1002']));

		return $input;
	}

    /**
     * 企业申请 数据验证
     *
     * @param Request $request
     * @return mixed
     * */
    public static function applyReg(Request $request)
    {
        $only = ['company_name','industry_id','scale','contact','verify_code','email','position','mobile'];

        $rules = [
			'company_name' => 'required|min:2|max:20',
            'industry_id' => 'required',
            'scale' => 'required',
            'verify_code' => 'required',
            'email' => 'required',
            'position' => 'required',
            'contact'=>'required',
            'mobile'=>'required',
        ];

        $messages = [
            'company_name.required' => '请输入公司名称',
            'company_name.min' => '公司名称不能小于2个字',
            'company_name.max' => '公司名称不能大于20个字',

            'industry_id.required' => '请输入所属行业',
            'scale.required' => '请输入公司规模',
            'verify_code.required' => '请输入验证码',
            'email.required' => '请输入管理员邮箱',
            'position.required' => '请输入职位',
            'contact.required' => '请输入企业联系人',
            'mobile.required' => '请输入企业联系人手机',
        ];

        $input = $request->only($only);

        $validator = Validator::make($input, $rules, $messages);

        if ($validator->fails())
            exit(json_encode(['info'=>$validator->errors()->first(),'code'=>'1002']));

        return $input;
    }

	/**
	 * @param Request $request
	 * @return array
	 * @name  学习卡申请
	 * @user IHammer
	 */
	public static function applyCardCreate(Request $request)
	{
		$only = ['company_name','industry_id','scale','contact','verify_code','email','position','mobile','card_pass'];

		$rules = [
				'company_name' => 'required|min:2|max:20',
				'industry_id' => 'required',
				'scale' => 'required',
				'verify_code' => 'required',
				'email' => 'required',
				'position' => 'required',
				'contact'=>'required',
				'mobile'=>'required',
				'card_pass'=>'required',
		];

		$messages = [
				'company_name.required' => '请输入公司名称',
				'company_name.min' => '公司名称不能小于2个字',
				'company_name.max' => '公司名称不能大于20个字',

				'industry_id.required' => '请输入所属行业',
				'scale.required' => '请输入公司规模',
				'verify_code.required' => '请输入验证码',
				'email.required' => '请输入管理员邮箱',
				'position.required' => '请输入职位',
				'contact.required' => '请输入企业联系人',
				'mobile.required' => '请输入企业联系人手机',
				'card_pass.required' => '请填写卡密',
		];

		$input = $request->only($only);

		$validator = Validator::make($input, $rules, $messages);

		if ($validator->fails())
			exit(json_encode(['info'=>$validator->errors()->first(),'code'=>'1002']));

		return $input;
	}



}